//
//  BasicBlock.h
//  ConstructGccfg2.0
//
//  Created by Bryce Holton on 12/4/12.
//  Copyright (c) 2012 Bryce Holton. All rights reserved.
//

#ifndef __ConstructGccfg2_0__BasicBlock__
#define __ConstructGccfg2_0__BasicBlock__

#include <iostream>
#include "common.h"
#include "Edge.h"

class BasicBlock
{
public:
    BasicBlock(int);
    virtual ~BasicBlock();
    int GetId();
    Color GetColor();
    void SetColor(Color);
    
    void SetDecendantEdge(BasicBlock &);
    vector<Edge<BasicBlock *> *> GetDecendantEdges();
    
    void SetAncestorEdge(Edge<BasicBlock *> &);
    vector<Edge<BasicBlock *> *> GetAncestorEdges();
    
    void SetLineOfCode(string);
    vector<string> GetCode();
    //Takes a function name as input and returns true if that function is
    //called from the blocks code.
    bool FindFunctionInCode(string &);
    
    //Finds first parameter in decendant list and replaces it with second parameter.
    void ReplaceChild(BasicBlock &, BasicBlock &);
    //Finds parameter in decendant list and removes it.
    void RemoveChild(BasicBlock &);
    //Finds the child block in this list of children.
    bool FindChild(BasicBlock &);
    //Prints block info; id, color, code
    virtual void Print();
    
private:
    int id;
    Color color;
    vector<Edge<BasicBlock *> *> decendantEdges;
    vector<Edge<BasicBlock *> *> ancestorEdges;
    vector<string> code;
    int FindEdgeIndex(BasicBlock &, vector<Edge<BasicBlock *> *> &);
    int DeleteDecendantEdge(BasicBlock &);
    int DeleteAncestorEdge(BasicBlock &);
    void InsertDecendantEdge(Edge<BasicBlock *> &, int);
    void InsertAncestorEdge(Edge<BasicBlock *> &, int);
};

#endif /* defined(__ConstructGccfg2_0__BasicBlock__) */
